from die import Die
import plotly.express as px

# 创建一个D6
die = Die()

# 掷几次色子并将结果存储在一个列表中
results = []
for roll_num in range(1000):
    result = die.roll()
    results.append(result)

# print(results)

# 分析结果
frequencies = []
poss_results = range(1, die.num_sides+1) # 色子六个面
# print(pross_results)
for value in poss_results:
    frequencies.append(results.count(value)) # 统计每个面出现的次数，并添加到分析结果frequencies列表中
    
print(frequencies)



# 图设置
title = "Results of Rolling One D6 1,000 Times"       
labels = {'x': 'Result', 'y': 'Frequency of Result'}  # x,y轴的标题

# 直方图
# fig = px.bar(x=poss_results, y=frequencies)   # 不设置x,y轴标题

# 点位图
# fig = px.scatter(x=poss_results, y=frequencies, title=title, labels=labels)

# 折线图
fig = px.line(x=poss_results, y=frequencies, title=title, labels=labels)
fig.show()